package com.zr.controller.base;

import java.util.List;
import com.zr.utils.AjaxResult;
import javax.annotation.Resource;
import com.zr.vo.base.BaseDriver;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;
import com.zr.service.base.BaseDriverService;
import org.springframework.web.bind.annotation.*;

/**
 * 司机增删改查
 */
@RestController
@RequestMapping("/baseDriver")
public class BaseDriverController {

    @Resource
    private BaseDriverService baseDriverService;

    /**
     * 条件查询司机信息列表
     * @param baseDriver
     * @return
     * @author liutienan
     */
    @RequestMapping("/list")
    public AjaxResult list(@RequestBody BaseDriver baseDriver){
        PageHelper.startPage(baseDriver.getPageNum(),baseDriver.getPageSize());
        List<BaseDriver> baseDriverList = baseDriverService.list(baseDriver);
        return AjaxResult.success(200, "查询成功", new PageInfo<>(baseDriverList));
    }

    /**
     * 查询所有司机信息
     * @return
     * @author liutienan
     */
    @RequestMapping("/listAll")
    public AjaxResult listAll(){
        List<BaseDriver> baseDriverList = baseDriverService.listAll();
        return AjaxResult.success(200, "查询成功", baseDriverList);
    }

    /**
     * 新增司机信息
     * @param baseDriver
     * @return
     * @author liutienan
     */
    @RequestMapping("/add")
    public AjaxResult add(@RequestBody BaseDriver baseDriver){
        baseDriverService.add(baseDriver);
        return AjaxResult.success(200, "新增成功", null);
    }

    /**
     * 修改司机信息
     * @param baseDriver
     * @return
     * @author liutienan
     */
    @RequestMapping("/edit")
    public AjaxResult edit(@RequestBody BaseDriver baseDriver){
        baseDriverService.edit(baseDriver);
        return AjaxResult.success(200, "修改成功", null);
    }

    /**
     * 删除司机信息
     * @param id
     * @return
     * @author liutienan
     */
    @RequestMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable("id") Integer id)  {
        baseDriverService.remove(id);
        return AjaxResult.success(200, "删除成功", null);
    }
}
